<!doctype html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>修改</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../css/mui.css" rel="stylesheet" />
		<link href="../../css/list.css" rel="stylesheet" />
		<script src="../../js/mui.min.js"></script>
		 <script src="../../js/app.js"></script>
		 <link href="../../css/style.css" rel="stylesheet" />
		 <link href="../../css/icons-extra.css" rel="stylesheet"/>
		 <link href="../../css/mui.poppicker.css" rel="stylesheet" />
		 <link href="../../css/mui.picker.css" rel="stylesheet"/>
		 <script src="../../js/mui.poppicker.js"></script>
		 <script src="../../js/mui.picker.js"></script>
		<link rel="stylesheet" href="../css/detail.css" type="text/css" />
		 		<style type="text/css">
.speak{
	/*输入框居中漂浮*/
/*position: absolute;
width:100%;
overflow: auto;
top: 50%;
padding: 0 5px;
text-align: center;*/
 /*width:100px;*/
      background:transparent;
      background:rgba(0,0,0,0.5);
      border-radius:8px;
      position: fixed;
      margin:auto;
      left:0; 
      right:0; 
      top:30%; 
      /*bottom:0;*/
      z-index: 1;
		 			}
</style>
</head>
<header class="mui-bar mui-bar-nav">
    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
  <h1 class="mui-title">项目概况<span id="title"></span></h1><p id="titleright" style="float: right;font-size: 0.6em;">举报</p>
</header>
    <div class="mui-content">
    <div  style="width:100%;margin:0 auto;text-align:center" id="image"></div>
    <div id="neirong" class="mui-content-padded"></div>
    <!--出品公司-->
    <li class="mui-content-padded" style="border-bottom:solid 1px #333;"><span style="padding:10px;color:red" onclick="imgup()">添加图片</span></li>
    <span id="img" class="slide-box"></span>
    <!--项目概况表格-->
    <div id="table" class="mui-content-padded"></div>

    </div>
    <div id="speak" class="speak" style="display: none;background: #DDDDDD;">
		<p id='speaktitle' style="margin:auto auto;font-size: 1.2em;color:#EC971F">请输入新内容</p>
		<textarea id="value" type="text"rows="8"placeholder="请输入"></textarea>
		<div style="margin-top: -24px;border-radius:5px;">
		<input id="pubish" style="font-size: 18px;margin: 2px 5px;padding:0 10px;float: right;" value="确认" type="submit">
		<input  style="font-size: 18px;margin: 2px 5px;float: right;padding:0 10px;" value="取消" type="submit" onclick="javascript:(document.getElementById('speak').style.display='none')">
		</div>
</div>
<script src="../../js/upload.js"></script>
<script src="../../Plugin/js/alertDIV.js"></script>
<script type="text/javascript">
	document.getElementById("image").addEventListener('tap', function() {
		mui.openWindow('../../Plugin/image/base64.html');
		
	})
	var tid=localStorage[htmlname+'id'];
	//发布关联团队返回触发函数
	window.addEventListener('renovate', function(e){
//		alert(JSON.stringify(e.detail));
	//主图裁剪上传返回数据执行更新
	  location.reload(); //刷新
	 });
	  //发布关联新闻返回触发函数
	window.addEventListener('refreshnews', function(e){
//		alert(JSON.stringify(e.detail));
	//主图裁剪上传返回数据执行更新
	  location.reload(); //刷新
	  });
function show_hidden(trid){
	var abc='';
	trid=document.getElementById(trid);
	if(trid.style.display=="block"){
	    trid.style.display='none';
	}else{
	    trid.style.display='block';
	}
}

value=document.getElementById('value');
   //输入框控制
function modifyinput(tid,key){
	speaktitle=document.getElementById('speaktitle');
	value.value=document.getElementById(key).innerText;
	document.getElementById('speak').style.display='block';//显示输入框
	var tid=tid||'';
	var key=key ||'';
		document.getElementById('pubish').onclick=function(){
			document.getElementById('speak').style.display='none';//隐藏发布按钮
			modify(tid,key);
			}
}
//删除div 下的id文档
function delete_html(thisid){
	var tid=document.getElementById(thisid);
	tid.parentNode.removeChild(tid);//删除div
}
//删除图片
function imgdelete(img,tid,act){
    mui.confirm('删除这条内容，确认？', '', ['否', '是'], function(e) {
        if (e.index == 1) {
        	apptoken['tid']=tid;
			apptoken['img']=img;
			//deleteteam=请求服务器删除团队简历
			apptoken['act']=act||'deleteteam';
			//relationoff=请求服务器关闭新闻动态挂载
			if(apptoken['act']=='relationoff'){
				//进入news新闻页处理
				apptoken['act']='modify';
				apptoken['v']='0';
				apptoken['k']='relationoff';
				mod='/news';
			}else{
				mod='/goods';
			}
	mui.post(home.hos+mod+'/admin',apptoken,function(data){//获取关联数据
//		alert(data);
	 	if(data==200){
	 		var tid=document.getElementById(img);
			tid.parentNode.removeChild(tid);//窗口文档中删除图片div
	 		plus.ui.toast('删除成功');
	 	}else{
	 		plus.ui.toast('操作失败');
	 	}})
        } else {
            plus.ui.toast('取消操作');
        }
       })
}

apptoken['tid']=tid;//获取详情id
apptoken['act']='detail';
mui.post(home.hos+'/goods/admin?tid='+apptoken['tid'],apptoken,function(data){
	alert(data);
	if(isJSON(data)){
		result=JSON.parse(data);//获取信息
		jsonarrfor(result);//加载详情信息

		}else{
			alert('页面加载失败，或不存在，请重新尝试');
			return false;
    	}
})
//主图大图
function imageplay(image,tid){
	document.getElementById('image').innerHTML='<img  style="width:95%;" src="'+home.uploads+'/img/goods/'+image+'" onerror="this.onerror=null;this.src=\'../../images/iconfont-tianjia.png\'" />';
}
function shelvesstatus(shelves){
//	if(result.status==1){
//	casestate='<span style="color:#00EE00;">●</span><span style="border-radius:25px;border:2px solid #a1a1a1;padding:2px 5px">聊聊</span>';
//}else{
//	casestate='<span style="color:red;">■</span>';
//}
	switch(shelves){
		case '0':
		shelves='<span style="color:red;">■</span>下架';
		  break;
		case '1':
		shelves='<span style="color:#00EE00;">●</span>上架';
		  break;
		default:
		shelves='';
		}
	return shelves;
}
var picker = new mui.PopPicker();
picker.setData([{
    value: "0",
    text: "下架"
}, {
    value: "1",
    text: "上架"
}])
function jsonarrfor(result){
	if(result.img){
		try {
				var rpic=result.img.split(",");//图片名
				for(var ib=0;ib<rpic.length;ib++){
				imgplay(rpic[ib],result.id);
				}
			}catch(err){
			
			}  
	}
//完成进度
var Completion=Math.round(result.sharenow/result.share*10000)/100;
//发布日期
var createtime=new Date(parseInt(result.createtime) * 1000).format('yyyy年M月d日');
//状态
var shelves='<option id="rtl1" value="1">上架</option><option value="0">下架</option>';

var val='<div style="text-align:center"><h3>'+result.classname+':'+result.title+'</h3><p  style="background: transparent;">状态<span style="border-radius:25px;border:2px solid #a1a1a1;padding:2px 5px" id="shelves" onchange="select('+result.id+',\'shelves\')">'+shelvesstatus(result.shelves)+'</span><span  style="background: transparent;">更新<select name="sel" id="rtl" onchange="select('+result.id+',\'shelves\')" style="height:2em;margin:2px;display:none;" >'+shelves+'</select></span></p></div>';


var table='<div class="list-head" ><table><tr><td width="110px">产品名称</td><td>'+result.title+'</td></tr><tr><td width="110px">类别</td><td>'+result.classname+'</td></tr><tr><td>单价</td><td><span id="price" >'+(result.price/100)+'</span>元[<span onclick="modifyinput('+result.id+',\'price\')" style="color:red">修改+</span>]</td></tr><tr><td>库存</td><td><span id="stock" >'+result.stock+'</span>[<span onclick="modifyinput('+result.id+',\'stock\')" style="color:red">修改+</span>]</td></tr><tr><td>已售出</td><td>'+result.sold+'</td></tr><tr><th  colspan="2" ><span style="text-align:center;">*详情*</span>[<span onclick="modifyinput('+result.id+',\'detail\')" style="color:red">修改+</span>]<p><span id="detail" >'+result.detail+'</span></p></th></tr></table></div>';
//形象头像
if(result.poster && result.poster.length>6){
imageplay(result.poster,result.id);	
}
//显示内容
document.getElementById('neirong').innerHTML=val;
document.getElementById('titleright').innerHTML='<div id="report" style="margin-top:10px;float:right">举报次数'+result.report+'</div>';
document.getElementById('table').innerHTML=table;

//上架触发下拉选择器
document.getElementById("shelves").addEventListener('tap', function() {
			picker.pickers[0].setSelectedValue(result.shelves, 2000);
			picker.show(function(SelectedItem) {
				var rtl=document.getElementById("rtl");
				  value.value=SelectedItem[0].value;
				  modify(result.id,'shelves');
				console.log(SelectedItem);
			})
        });
}

//修改组件
function modify(tid,type){
	//k=键；act=修改方法，tid=主题id，type=修改类型；
	apptoken['k']=type||'';
	if(type=='detail' || type==''){//如果修改的页面是内容多行文本，将会替换换行符
	apptoken['v']=getFormatCode(value.value) ||'';
	//价格修改*100
	}else if(type==="price"){
		apptoken['v']=value.value*100;
	}else{
		apptoken['v']=value.value ||'';
	}
	apptoken['tid']=tid||'';
	apptoken['act']='modify';
	mui.post(home.hos+'/goods/admin',apptoken,function(data){
//		alert(data);
		if(isJSON(data)){
//			alert(value.value);
			jsondata=JSON.parse(data);
			if(jsondata.status && jsondata.status==200){
				//上架状态
				if(type=='shelves'){
					value.value=shelvesstatus(value.value);
				}
				document.getElementById(type).innerHTML=value.value;
				plus.ui.toast('操作成功');
			}else{
				plus.ui.toast('操作失败');
			}
			//修改加密状态显示/或者加密
//			encrypystatus(jsondata.encrypt,tid);
		}
	})
}

function imgdelete(img,tid){
	if (confirm("确定要删除这张图片吗？")) { 
//	delete_html("con"+img);
	apptoken['tid']=tid;
	apptoken['img']=img;
//	apptoken['type']=type;
	apptoken['act']='deleteimg';
//	alert(JSON.stringify(apptoken));
	mui.post(home.hos+'/goods/admin',apptoken,function(data){//获取关联数据
//		alert(data);
	 	if(data==1){
	 		var tid=document.getElementById('con'+img);
			tid.parentNode.removeChild(tid);//窗口文档中删除图片div
	 		plus.ui.toast('删除成功');
	 	}else{
	 		plus.ui.toast('操作失败');
	 	}
	})
	 } 
    else { 
      plus.ui.toast('操作取消'); 
    } 
}
var type=64;//可不填。返回类型（file/64base）;
var imgnames='imgs';//img对应的name值
var upload=new uploadimg(imgsplay,type);//实例化类

function imgsplay(path){//两个参数path必填是图片路径，type=64可填，返回数据类型。默认不填返回图片源文件,64=返回64base压缩类型
if(type===64){//判断是否需要64base转码压缩
		var image = new Image();
			image.src = path;  
			image.onload = function(){
			var img_typearr=['jpeg','jpg','bmp','png'];//支持格式类型
			_type=upload.appendFile(img_typearr,path);//检查是否支持,返回false 或者后缀名
//			alert(_type);
			if(_type){
			var is_type="image/jpeg";//压缩格式
			var ratio=0.9;//压缩质量
			var width=1080;//压缩后最长边距像素；
		    path = compress(image,width, ratio,is_type);//压缩图片转成64base后显示
		    img=document.getElementById('img');
		    apptoken['img']=path;
		    apptoken['act']='upimg';
		    mui.post(home.hos+'/goods/admin',apptoken,function(data){//获取关联数据
//		    	alert(data); 
		    	if(isJSON(data)){
		    		var imgarr=JSON.parse(data);
				    var status=imgarr['status'] || '';
				    if(imgarr.status==200){
				    	 imgplay(imgarr.img,apptoken['tid']);//图片追加到html
				 		plus.ui.toast('上传成功');
				 	}else{
				 		plus.ui.toast('上传失败');
				 	}
		    	}else{
		    		alert('打开失败，请从新尝试');
		    		return false;
		    	}
		    
		})
			}
return false;}
}else{
	 alert('不支持的类型'+path);
//	imgplay(path);
}
};
function delete_html(thisid){
	var tid=document.getElementById(thisid);
	tid.parentNode.removeChild(tid);//删除div
}
function imgplay(imgname,tid){//把图片追加到窗口
	html='<li class="pic"  id="con'+imgname+'" style="max-width:100px;min-height:10px;padding:3px;position:relative" ><span style="position:absolute;background:#FF6A6A;text-align:center;border-radius:6px;color:#fff;padding:1px 4px;">x</span><img id="'+imgname+'" style="margin:0;width:100%;max-width:100px;" onclick="imgdelete(\''+imgname+'\',\''+tid+'\')" src="'+home.uploads+'/img/goods/min'+imgname+'" onerror="this.onerror=null;this.src=\'../../images/logo.png\'"  /></li>';
//	document.getElementById("img").innerHTML+=html;
	appendChild("img",html,'1');
}
function imgup(){
	var cs=document.getElementById("img").getElementsByTagName("li");
		var maxnum=9-cs.length;//限制上传图片数量
		var lasnum=9-cs.length;
		if(lasnum<=0){
			alert('最多只能上传9张图片');
			return false;
		}
	var lasnum=maxnum-document.getElementsByName(imgnames).length;
	upload.addImage(maxnum,lasnum,'imglist');//图片img外层id
}
  </script>